package com.hello.booksale.util;


import org.springframework.http.*;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;

public class RecaptchaUtil {

    public static Boolean verify(String resp) {

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8));
        String uri = "https://www.recaptcha.net/recaptcha/api/siteverify?secret=6Lfo1VQjAAAAAFa5xdAeidxQTE1n5K8tCKnZx8E-&response="+resp;
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType("application/x-www-form-urlencoded;charset=UTF-8"));
        HttpEntity<String> entity = new HttpEntity<>(headers);
        ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET,entity, String.class);
//        String status=jsonObject.getString("success");
//        System.out.println("状态: "+status);
        System.out.println(response.getBody());
        return true;
    }
}
